﻿Imports Co9320.NamaAlert.Model
Imports System.Windows

<Plugin("F1E417E1-EF49-4e5d-8783-F9A882AF7FBD", _
        HasAlertFunction:=True)> _
Public Class BalloonAlert
    Implements IPlugin

    Public Event RequestShowAlertWindow(ByVal sender As Object, ByVal e As ShowAlertWindowEventArgs) Implements IPlugin.RequestShowAlertWindow
    Public Event RequestShowBalloonTip(ByVal sender As Object, ByVal e As ShowBalloonTipEventArgs) Implements IPlugin.RequestShowBalloonTip
    Public Event RequestOpenUri(ByVal sender As Object, ByVal e As OpenUriEventArgs) Implements IPlugin.RequestOpenUri
    Public Event SendSystemMessage(ByVal sender As Object, ByVal e As SystemMessageEventArgs) Implements IPlugin.SendSystemMessage
    Public Event RequestSaveSettings(ByVal sender As Object, ByVal e As SaveSettingsEventArgs) Implements IPlugin.RequestSaveSettings

    Public Sub Initialize(ByVal settings As IPluginSettings) Implements IPlugin.Initialize
        ' Do nothing
    End Sub

    Public Sub EditOptions(ByVal dialogOwner As Window) Implements IPlugin.EditOptions
        Throw New NotSupportedException
    End Sub

    Public Sub ExecuteAlert(ByVal program As Model.LiveProgram) Implements IPlugin.ExecuteAlert
        Dim sb = New System.Text.StringBuilder

        ' Content 2個以上連続の改行は1個に置換
        Dim content = System.Text.RegularExpressions.Regex.Replace(program.Content, "[\n\r]+\s*[\n\r]+", vbCrLf, Text.RegularExpressions.RegexOptions.Singleline)
        sb.Append(content.Trim & vbCrLf)

        ' 放送局
        sb.Append(program.Station.Name)

        ' 放送者名（ない場合あり）
        If program.CasterName IsNot Nothing Then
            sb.Append(" (" & program.CasterName & ")")
        End If
        sb.Append(vbCrLf)

        ' 各種情報
        If program.Station.Kind = StationKind.Community AndAlso program.IsReserved Then
            sb.Append("[予約]")
        ElseIf program.Station.Kind = StationKind.Channel Then
            'sb.Append("[ch]")
        End If
        If program.IsMemberOnly Then
            sb.Append("[限定]")
        End If
        If program.OfficialTag <> "" Then

            Dim dictionary = New Dictionary(Of String, String)

            dictionary.Add("一般(その他)", "一般")
            'dictionary.Add("政治", "")
            'dictionary.Add("動物", "")
            'dictionary.Add("料理", "")
            dictionary.Add("演奏してみた", "演奏")
            dictionary.Add("歌ってみた", "歌")
            dictionary.Add("踊ってみた", "踊")
            'dictionary.Add("講座", "")
            dictionary.Add("ゲーム実況", "ゲーム")
            dictionary.Add("動画紹介・リクエスト", "動リク")
            'dictionary.Add("R18", "")

            sb.Append(String.Format(System.Globalization.CultureInfo.CurrentCulture, "[{0}]", program.OfficialTag))
        End If
        If program.IsFace Then
            sb.Append("[顔出]")
        End If

        OnRequestShowBalloonTip(New ShowBalloonTipEventArgs(New BalloonTipContext(program.Title, sb.ToString, program.Uri)))
    End Sub

    Public Sub ExecuteAction(ByVal program As LiveProgram) Implements IPlugin.ExecuteAction
        Throw New NotSupportedException
    End Sub

    Public Sub ExecuteWhenLiveProgramStarted(ByVal liveProgram As LiveProgram) Implements IPlugin.ExecuteWhenLiveProgramStarted
        Throw New NotSupportedException
    End Sub

    Protected Sub OnRequestShowBalloonTip(ByVal e As ShowBalloonTipEventArgs)
        RaiseEvent RequestShowBalloonTip(Me, e)
    End Sub

End Class
